<?php

namespace Tuobaye\FilamentAdmin;


use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Tuobaye\FilamentAdmin\Commands\FilamentAdminInstall;
use Tuobaye\FilamentAdmin\Commands\GenerateAdmin;
use Tuobaye\FilamentAdmin\Commands\LivewireLink;
use Tuobaye\FilamentAdmin\Models\User;

class FilamentAdminServiceProvider extends PackageServiceProvider
{
    public function configurePackage(Package $package): void
    {
        /*
         * This class is a Package Service Provider
         *
         * More info: https://github.com/spatie/laravel-package-tools
         */
        $package
            ->name('filament-admin')
            ->hasConfigFile()
            ->hasMigrations([
                'create_admin_users_table',
                'create_admin_roles_table',
                'create_admin_role_permissions_table',
                'create_admin_user_role_table'
            ])
            ->hasViews()
            ->hasCommands(GenerateAdmin::class, LivewireLink::class, FilamentAdminInstall::class);
    }

    public function bootingPackage(): void
    {
        config(['auth.guards.' . config('filament-admin.auth.guard') => [
            'driver' => 'session',
            'provider' => config('filament-admin.auth.guard') . '_admins',
        ]]);

        config([
            'auth.providers.' . config('filament-admin.auth.guard') . '_admins' => [
                'driver' => 'eloquent',
                'model' => User::class,
            ]
        ]);
    }
}
